home *** CD-ROM | disk | FTP | other *** search
/ Savor the Moment - Entert…ing Without Reservations / Savoe the Moment - Entertaining Without Reservations.iso / pc / Full_In / _SETUP.1 / Main Menu.dxr / 00030_Display Text.ls < prev    next >
Encoding:
Text File  |  1999-10-05  |  9.3 KB  |  196 lines

  1. property spriteNum, getPDLError, myDisplayType, mySprite, myMember, myWidthAdjust, myHeightAdjust, myOffStageLoc
  2.  
  3. on getBehaviorDescription me
  4.   return "DISPLAY TEXT" & RETURN & RETURN & "This behavior allows you to display a given string in a Field or Text member.  Use it with the 'Tooltip' and 'Hypertext - Display Status' behaviors which need a Field or Text member in which to display their information.  Or create your own custom Lingo to display runtime information, such as the position of the mouse." & RETURN & RETURN & "This behavior waits for Lingo commands to tell it what to do.  It is not active by itself." & RETURN & RETURN & "You can choose between two display types: tooltip and status bar." & RETURN & RETURN & "The TOOLTIP type of display will make the Field or Text member resize itself to fit the text, and disappear when it is empty.  You can set the tooltip type display to appear at any position on the stage, for example: under the cursor.  If no position is sent to the sprite, it will appear at the top left corner of the Stage.  See the 'Tooltip' behavior for more details." & RETURN & RETURN & "If you wish to display several lines of text, you must use RETURN characters to define the line breaks.  An empty tooltip sprite will move off-stage to hide.  It is recommended to place it off-stage before it is used, in case it causes a brief flash on the screen." & RETURN & RETURN & "The STATUS BAR type of display will appear on Stage at all times.  It will not resize or change position.  Any positional information sent to this sprite will be ignored if it is set to act as a status bar.  If the text is too long to appear in the member of the current sprite, a scrollbar will appear.  You do not need to divide the text with RETURN characters.  If you think that a scrollbar may be necessary, make sure that the Field or Text member is sufficiently tall for the scroll arrows to operate correctly." & RETURN & RETURN & "Set the font size and other characteristics of Field or Text member to customize the appearance of the message." & RETURN & RETURN & "Be sure to give the Text or Field member a name.  It may be emptied by this behavior.  Director 7 automatically erases nameless empty members." & RETURN & RETURN & "PERMITTED MEMBER TYPES:" & RETURN & "Field and Text members" & RETURN & RETURN & "PARAMETERS:" & RETURN & "* Display type:" & RETURN & "  - Tooltip (appears near the cursor on rollover)" & RETURN & "  - Status bar (appears in a fixed position at all times)" & RETURN & RETURN & "ASSOCIATED BEHAVIORS:" & RETURN & "+ Tooltip" & RETURN & "+ Source Status" & RETURN & "+ Hypertext - Display Status" & RETURN & RETURN & "PUBLIC METHODS:" & RETURN & "=> Set the text to display (and the position of the sprite)"
  5. end
  6.  
  7. on getBehaviorTooltip me
  8.   return "Use with Field or Text members." & RETURN & RETURN & "This behavior waits for a message to display a character string." & RETURN & "It is intended to be used with the 'Tooltip', 'Source Status' and" & RETURN & "'Hypertext - Display Status' behaviors to create a tooltip under the cursor, or a" & RETURN & "status bar in a fixed position.  You can also use it with your" & RETURN & "own custom Lingo, to display the result of an operation for example." & RETURN & RETURN & "It is a passive behavior which does nothing meaningful on its own."
  9. end
  10.  
  11. on beginSprite me
  12.   Initialize(me)
  13. end
  14.  
  15. on endSprite me
  16.   mySprite.visible = 1
  17. end
  18.  
  19. on Initialize me
  20.   mySprite = sprite(me.spriteNum)
  21.   myMember = mySprite.member
  22.   memberType = myMember.type
  23.   case memberType of
  24.     #field, #text:
  25.     otherwise:
  26.       return ErrorAlert(me, #invalidMemberType, memberType)
  27.   end case
  28.   myDisplayType = symbol(myDisplayType)
  29.   if myMember.type = #field then
  30.     myWidthAdjust = (myMember.margin + myMember.border) * 2
  31.     myHeightAdjust = myMember.margin + (myMember.border * 2)
  32.   else
  33.     myWidthAdjust = 0
  34.     myHeightAdjust = 0
  35.   end if
  36.   myMember.text = EMPTY
  37.   if myDisplayType = #Tooltip then
  38.     myMember.boxType = #fixed
  39.     myOffStageLoc = point(999, 999)
  40.     mySprite.loc = myOffStageLoc
  41.   end if
  42. end
  43.  
  44. on BestRect me, theString
  45.   myMember.rect = rect(0, 0, 8000, 0)
  46.   myMember.text = theString
  47.   BestRect = myMember.rect
  48.   theLine = the number of lines in theString
  49.   theWidth = 0
  50.   checkedChars = 0
  51.   repeat while theLine
  52.     endOfLine = offset(RETURN, theString)
  53.     if not endOfLine then
  54.       endOfLine = the number of chars in theString + 1
  55.       myMember.text = myMember.text & RETURN
  56.     end if
  57.     checkedChars = checkedChars + endOfLine
  58.     endPoint = charPosToLoc(myMember, checkedChars)
  59.     lineWidth = endPoint[1]
  60.     if lineWidth > theWidth then
  61.       theWidth = lineWidth
  62.     end if
  63.     delete char 1 to endOfLine of theString
  64.     theLine = theLine - 1
  65.   end repeat
  66.   lastChar = myMember.char.count
  67.   lastCharLoc = charPosToLoc(myMember, lastChar)
  68.   theHeight = lastCharLoc[2]
  69.   BestRect[3] = theWidth + 1
  70.   BestRect[4] = theHeight + 1
  71.   return BestRect
  72. end
  73.  
  74. on GetTopLeft me, theLoc, theAlignment, memberRect
  75.   case theAlignment of
  76.     #bottomCenter:
  77.       return theLoc - [memberRect.width / 2, memberRect.height]
  78.     #bottomRight:
  79.       return theLoc - [memberRect.width, memberRect.height]
  80.     #bottomLeft:
  81.       return theLoc - [0, memberRect.height]
  82.     #center:
  83.       return theLoc - [memberRect.width / 2, memberRect.height / 2]
  84.     #topCenter:
  85.       return theLoc - [memberRect.width / 2, 0]
  86.     #topRight:
  87.       return theLoc - [memberRect.width, 0]
  88.     otherwise:
  89.       return theLoc
  90.   end case
  91. end
  92.  
  93. on DisplayText_Enroll me, enrollList
  94.   if ilk(enrollList) <> #list then
  95.     return me
  96.   end if
  97.   if not enrollList.count() then
  98.     enrollList.append(me)
  99.   else
  100.   end if
  101.   return enrollList
  102. end
  103.  
  104. on DisplayText_SetText me, theString, theLoc, theAlignment
  105.   if not stringp(theString) then
  106.     ErrorAlert(me, #invalidString, theString)
  107.     theString = string(theString)
  108.   else
  109.     case ilk(theLoc) of
  110.       #void, #point:
  111.       otherwise:
  112.         ErrorAlert(me, #invalidPoint, theLoc)
  113.         theLoc = point(0, 0)
  114.     end case
  115.   end if
  116.   if (theString = EMPTY) and (myDisplayType = #Tooltip) then
  117.     mySprite.loc = myOffStageLoc
  118.   else
  119.     myMember.text = theString
  120.     if myDisplayType = #Tooltip then
  121.       memberRect = BestRect(me, theString)
  122.       myMember.rect = memberRect
  123.     else
  124.       memberRect = myMember.rect
  125.     end if
  126.     memberRect = memberRect + [0, 0, myWidthAdjust, myHeightAdjust]
  127.     if myDisplayType = #Tooltip then
  128.       if ilk(theLoc) <> #point then
  129.         theLoc = point(0, 0)
  130.       end if
  131.       theLoc = GetTopLeft(me, theLoc, theAlignment, memberRect)
  132.       stageWidth = (the activeWindow).rect.right - (the activeWindow).rect.left
  133.       stageHeight = (the activeWindow).rect.bottom - (the activeWindow).rect.top
  134.       maxH = stageWidth - memberRect.width
  135.       maxV = stageHeight - memberRect.height
  136.       theLoc[1] = max(0, min(theLoc[1], maxH))
  137.       theLoc[2] = max(0, min(theLoc[2], maxV))
  138.       theLoc = theLoc + myMember.regPoint
  139.       mySprite.loc = theLoc
  140.     else
  141.       lastChar = theString.char.count
  142.       textHeight = charPosToLoc(myMember, lastChar)[2]
  143.       if textHeight > mySprite.height then
  144.         myMember.boxType = #scroll
  145.       else
  146.         myMember.boxType = #fixed
  147.       end if
  148.     end if
  149.   end if
  150. end
  151.  
  152. on DisplayText_GetReference me
  153.   return me
  154. end
  155.  
  156. on ErrorAlert me, theError, data
  157.   case theError of
  158.     #getPDLError:
  159.       alert("Error: This behavior works only with Field and Text members." & RETURN & RETURN & "Hit OK and then delete this behavior from the sprite." & RETURN & RETURN & "For more information on deleting Behaviors, see the Help system.")
  160.       if the optionDown then
  161.         return [#getPDLError: [#comment: "ERROR:   Wrong member type.   Click 'Cancel'." & RETURN & "             Use only with Field and Text members.", #format: #string, #range: [EMPTY], #default: EMPTY]]
  162.       end if
  163.     otherwise:
  164.       case theError of
  165.         #invalidMemberType:
  166.           behaviorName = string(me)
  167.           delete word 1 of behaviorName
  168.           delete char -30001 of behaviorName
  169.           delete char -30001 of behaviorName
  170.           alert("BEHAVIOR ERROR: Frame " & the frame & ", Sprite " & me.spriteNum & RETURN & RETURN & "Behavior " & behaviorName & " only works with Field and Text members." & RETURN & RETURN & "Current member type = #" & data)
  171.           halt()
  172.         #invalidString:
  173.           if the runMode = "Author" then
  174.             alert("BEHAVIOR ERROR: Frame " & the frame & ", Sprite " & me.spriteNum & RETURN & "Behavior " & behaviorName & RETURN & RETURN & "The DisplayText_SetText handler could not treat the following as a string:" & RETURN & RETURN & data)
  175.           end if
  176.         #invalidPoint:
  177.           if the runMode = "Author" then
  178.             alert("BEHAVIOR ERROR: Frame " & the frame & ", Sprite " & me.spriteNum & RETURN & "Behavior " & behaviorName & RETURN & RETURN & "The DisplayText_SetText handler could not treat the following as a point:" & RETURN & RETURN & data)
  179.           end if
  180.       end case
  181.   end case
  182. end
  183.  
  184. on getPropertyDescriptionList me
  185.   if not (the currentSpriteNum) then
  186.     exit
  187.   end if
  188.   theMember = sprite(the currentSpriteNum).member
  189.   case theMember.type of
  190.     #field, #text:
  191.     otherwise:
  192.       return ErrorAlert(me, #getPDLError)
  193.   end case
  194.   return [#myDisplayType: [#comment: "Display Text sprite behaves as a:", #format: #symbol, #range: ["status bar (fixed size and position)", "tooltip (dynamic size and position)"], #default: "in a fixed position (status bar)"]]
  195. end
  196.